{template 'common/header'}
<link href="{MODULE_URL}template/web/css/classlist.css" rel="stylesheet" type="text/css">
  <ul class="nav nav-tabs">    
    <li><a href="{php echo $this->createWebUrl('setCard');}">微信卡券</a></li>
    <li class="active" ><a href="{php echo $this->createWebUrl('setMiicard');}">系统优惠券</a></li>
    <li><a href="{php echo $this->createWebUrl('setmembercard');}">会员卡设置</a></li>
    <li><a href="{php echo $this->createWebUrl('setcardoff');}">卡券核销</a></li>
  </ul>
    <div class="list_th">
        <div class="td" style=" width:20%;">
         <div class="left_padding">卡券标题</div>
        </div>
        <div class="td text-center" style=" width:10%;">卡券类型</div>
        <div class="td text-center" style=" width:20%;">有效期限</div>
        <div class="td text-center" style=" width:10%;">卡券库存</div>
        <div class="td text-center" style=" width:10%;">卡券限领</div>
        <div class="td text-center" style=" width:10%;">系统状态</div>
        <div class="td text-center" style=" width:20%;">
            <div class="list_right text-center">操作</div>
        </div>
        <div class="clear"></div>
    </div>
    {if $card}
    {loop $card $k $o}
    <div class="list_tr link_bk">
            <div class="td" style=" width:20%;">
               <div class="left_padding"> {$o['title']}</div>
            </div>
            <div class="td text-center" style=" width:10%;" >
                {php echo cardname($o['card_type'])}
            </div> 
            <div class="td text-center" style=" width:20%;" >
                {if $o['starttime']}
                    {php echo date('Y-m-d',$o['starttime'])}/{php echo date('Y-m-d',$o['endtime'])}
                {else}
                    {php echo date_info($o['date_info'])}
                {/if}
            </div>
            <div class="td text-center" style=" width:10%;" >
                {$o['quantity']}/{$o['total_quantity']}
            </div>      
            <div class="td text-center" style=" width:10%; color: #ff5d38;" >
                {$o['get_limit']}
            </div>       
            <div class="td text-center" style=" width:10%;" >
                {if $o['status']=='1'}上架中{else}已下架{/if}
            </div>                   
            <div class="td edit text-center" style=" width:20%;">
                <div class="list_right btn">
                    <a class="gray status" style="background-color: #ff5d38;" sid="{$o['status']}" cid="{$o['id']}">{if $o['status']=='1'}下架{else}上架{/if} </a>
                    <a class="gray" style="background-color: #8A2BE2;" href="{php echo $this->createWebUrl('cardedit',array('cid'=>$o['id']));}" cid="{$o['id']}">编辑</a>
                    <a class="gray delete" cid="{$o['id']}">删除</a>
                </div>
            </div>
            <div class="clear"></div>
        </div>
    {/loop}
    {else}  
    {/if}
<div class="list_tr">
    <div class="td" style="width: 60%;">
        <a class="J_add category_list_add" level="1" pid="0" href="{php echo $this->createWebUrl('cardadd');}">添加优惠券</a>
        <div class="clear"></div>
    </div>
</div>    
<div class="list_tr">    
<div class="text-center">
  {php echo $pager;}
</div> 
</div>
<style type="text/css">.right-content{padding: 0;}.hot_1{background-color: red;}</style>
<link rel="stylesheet" href="{MODULE_URL}public/css/Toast.css">
<script src="{MODULE_URL}public/js/Toast.js"></script>  
<script type="text/javascript">
    $(".status").on("click",function(){
        var _this = $(this)
        var sid = $(this).attr('sid');
        var asid = $(this).attr('sid')==1?0:1;
        var cid = _this.attr('cid');
        $.ajax({
             url:"{php echo $this->createWebUrl('cardstatus');}&version_id="+"{$_GPC['version_id']}",
             data:{sid:sid,cid:cid},
             dataType:"json",
             type:"post",
            success:function(res){
                if(res.status==1){
                    mqToast({type:1,context: res.msg})
                    setTimeout(function(){
                        window.location.reload();
                      },1000);                    
                }else{
                   mqToast({type:1,context: res.msg}) 
               }
            }
        })
    });
    $(".delete").on("click",function(){
        var cid = $(this).attr('cid');
        if(!confirm("确定要删除该卡券吗！")){                
                   window.event.returnValue=false;
               }else{
                $.ajax({
                     url:"{php echo $this->createWebUrl('carddelete');}&version_id="+"{$_GPC['version_id']}",
                     data:{cid:cid},
                     dataType:"json",
                     type:"post",
                success:function(res){
                    if(res.status=='1'){
                        mqToast({type:1,context: res.msg})
                        setTimeout(function(){
                            window.location.reload();
                          },1000); 
                    }else{
                        mqToast({type:1,context: res.msg})
                    }
                }
                })

               }

    });

    $(".upcard").on("click",function(){
        $('#upcard').addClass('disabled');
        $.ajax({
             url:"{php echo $this->createWebUrl('upcardstatus');}&version_id="+"{$_GPC['version_id']}",
             data:{},
             dataType:"json",
             type:"post",
            success:function(res){
                if(res.status=='1'){
                    mqToast({type:1,context: res.msg})
                    setTimeout(function(){
                        window.location.reload();
                      },1000); 
                }else{
                    mqToast({type:1,context: res.msg})
                }
            }
        })

    });    

</script>
{template 'common/footer'}